package com.weiaibenpao.demo.chislim.db.preferences;

import android.content.Context;
import android.content.SharedPreferences;

import com.weiaibenpao.demo.chislim.MyApplication;

/**
 * Created by ZJL on 2017/8/5.
 */

public class RunningPreferences {

    private static final String RUNNING_PREFERENCE_NAME = "running_info";
    private static final String RUNNING_ACTIVITY = "running_activity";//当前的跑步界面  也可作为类型
    private static final String RUNNING_STATE = "running_state";
    private static final String RUNNING_TIME = "running_time";
    private static final String RUNNING_DISTANCE = "running_distance";
    private static final String RUNNING_PACE = "running_pace";        //配速
    private static final String RUNNING_CALORIE = "running_calorie";
    private static final String RUNNING_STEP = "running_step";
    private static final String LAST_CALCULATE_DISTANCE ="last_calculate_distance";
    private static final String LAST_CALCULATE_RUNNING_TIME ="last_calculate_running_time";
    private static final String LAST_KM_DISTANCE = "last_km_distance";
    private static final String LAST_KM_RUNNING_TIME = "last_km_running_time";
    private static final String LAST_CALCULATE_STEP_COUNT ="last_calculate_step_count";

    public static final String CITY_CODE="code";//行政跑
    public static final String PROVINCE="province";
    public static final String RUN_DISTANCE="runDistance";//已跑总里程
    public static final String DISTRICT_DISTANCE = "districtDistance";
    public static final String SPORT_TYPE = "sportType";

    public static final String IS_PERSONAL_MARATHON ="is_personal_marathon";
    public static final String IS_INDOOR_RUNNING ="is_indoor_running";


    private SharedPreferences mPref;

    public static RunningPreferences getInstance() {
        return PreferenceHolder.sInstance;
    }

    private static class PreferenceHolder {
        private static final RunningPreferences sInstance = new RunningPreferences();
    }


    private RunningPreferences() {
        mPref = MyApplication.getInstance().getSharedPreferences(RUNNING_PREFERENCE_NAME, Context.MODE_PRIVATE);
    }

    public void putBoolean(String key,boolean boolValue){
        SharedPreferences.Editor editor = mPref.edit();
        editor.putBoolean(key,boolValue).apply();
    }

    public boolean getBoolean(String key){
        return mPref.getBoolean(key,false);
    }


    public void putString(String key ,String strValue){
        SharedPreferences.Editor editor = mPref.edit();
        editor.putString(key, strValue).apply();
    }

    public String getString(String key){
        return mPref.getString(key,"");
    }

    public void putInt(String key ,int intValue){
        SharedPreferences.Editor editor = mPref.edit();
        editor.putInt(key,intValue).apply();
    }

    public int getInt(String key){
        return mPref.getInt(key,0);
    }

    public void putLong(String key,long longValue){
        SharedPreferences.Editor editor = mPref.edit();
        editor.putLong(key,longValue).apply();
    }

    public long getLong(String key){
        return mPref.getLong(key,0);
    }

    public void putFloat(String key,float floatValue){
        SharedPreferences.Editor editor = mPref.edit();
        editor.putFloat(key,floatValue).apply();
    }

    public float getFloat(String key){
        return mPref.getFloat(key,0f);
    }

    public void setRunningActivity(String runningActivity) {
        SharedPreferences.Editor editor = mPref.edit();
        editor.putString(RUNNING_ACTIVITY, runningActivity).apply();
    }

    public String getRunningActivity() {
        String runningActivity = mPref.getString(RUNNING_ACTIVITY, "");
        return runningActivity;
    }

    public void setRunningState(int state) {
        SharedPreferences.Editor editor = mPref.edit();
        editor.putInt(RUNNING_STATE, state).apply();
    }

    public int getRunningState() {
        return mPref.getInt(RUNNING_STATE, 0);
    }

    public void setRunningTime(int time) {
        SharedPreferences.Editor editor = mPref.edit();
        editor.putInt(RUNNING_TIME, time).apply();
    }

    public int getRunningTime() {//单位秒
        return mPref.getInt(RUNNING_TIME, 0);
    }

    public void setRunningDistance(float distance) {
        SharedPreferences.Editor editor = mPref.edit();
        editor.putFloat(RUNNING_DISTANCE, distance).apply();
    }

    public float getRunningDistance() {
        return mPref.getFloat(RUNNING_DISTANCE, 0f);
    }

    public void setRunningPace(String pace) {
        SharedPreferences.Editor editor = mPref.edit();
        editor.putString(RUNNING_PACE, pace).apply();
    }

    public String getRunningPace() {
        return mPref.getString(RUNNING_PACE, "0'00''");
    }

    public void  setRunningStep(int steps){
        SharedPreferences.Editor editor = mPref.edit();
        editor.putInt(RUNNING_STEP,steps).apply();
    }

    public int getRunningStep(){
        return mPref.getInt(RUNNING_STEP,0);
    }

    public void setLastCalculateStepCount(int stepCount){
        SharedPreferences.Editor editor = mPref.edit();
        editor.putInt(LAST_CALCULATE_STEP_COUNT,stepCount).apply();
    }

    public int getLastCalculateStepCount(){
        return mPref.getInt(LAST_CALCULATE_STEP_COUNT,0);
    }

    public void setRunningCalorie(String calories){
        SharedPreferences.Editor editor = mPref.edit();
        editor.putString(RUNNING_CALORIE,calories).apply();
    }

    public String getRunningCalorie(){
        return mPref.getString(RUNNING_CALORIE,"0");
    }

    public void setLastKmDistance(float kmDistance){
        SharedPreferences.Editor editor = mPref.edit();
        editor.putFloat(LAST_KM_DISTANCE,kmDistance).apply();
    }

    public float getLastKmDistance(){
        return mPref.getFloat(LAST_KM_DISTANCE,0f);
    }

    public void setLastKmRunningTime(int time){
        SharedPreferences.Editor editor = mPref.edit();
        editor.putInt(LAST_KM_RUNNING_TIME,time).apply();
    }

    public int getLastKmRunningTime(){
        return mPref.getInt(LAST_KM_RUNNING_TIME,0);
    }

    public void setLastCalculateDistance(float lastDistance){
        SharedPreferences.Editor editor = mPref.edit();
        editor.putFloat(LAST_CALCULATE_DISTANCE,lastDistance).apply();
    }

    public float getLastCalculateDistance(){
        return mPref.getFloat(LAST_CALCULATE_DISTANCE,0f);
    }

    public void setLastCalculateRunningTime(int time){
        SharedPreferences.Editor editor = mPref.edit();
        editor.putInt(LAST_CALCULATE_RUNNING_TIME,time).apply();
    }

    public int getLastCalculateRunningTime(){
        return mPref.getInt(LAST_CALCULATE_RUNNING_TIME,0);
    }


    /**
     * 城市编码
     * @param code
     */
    public void setDistrictCode(String code) {
        SharedPreferences.Editor editor = mPref.edit();
        editor.putString(CITY_CODE, code).apply();
    }
    public String getDistrictCode() {
        return mPref.getString(CITY_CODE, "330100");

    }
/**
 * 城市名称
 */
    public void setDistrict(String code) {
    SharedPreferences.Editor editor = mPref.edit();
    editor.putString(PROVINCE, code).apply();
}
    public String getDistrict() {
        return mPref.getString(PROVINCE, "浙江省杭州市");

    }
    /**
     * 城市距离
     * @param districtDistance
     */
    public void setDistrictDistance(float districtDistance) {
        SharedPreferences.Editor editor = mPref.edit();
        editor.putFloat(DISTRICT_DISTANCE, districtDistance).apply();
    }
    public float getDistrictDistance() {
        return mPref.getFloat(DISTRICT_DISTANCE, 0f);

    }

    public void setRunDistance(float districtDistance) {
        SharedPreferences.Editor editor = mPref.edit();
        editor.putFloat(RUN_DISTANCE, districtDistance).apply();
    }
    public float getRunDistance() {
        return mPref.getFloat(RUN_DISTANCE, 0f);
    }
    public void setSportType(int sportType){
        SharedPreferences.Editor editor = mPref.edit();
        editor.putFloat(SPORT_TYPE, sportType).apply();
    }
    public float getSportType() {
        return mPref.getFloat(SPORT_TYPE, 0f);
    }
    public void clear() {
        mPref.edit().clear().apply();
    }

}
